<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        nums=[1,2,3,4,5,6,8,12,30]
        target = 7
       var search = function(nums, target) {
    var mid = nums.length%2==0 ? nums.length/2-1 :nums.length/2-0.5
    mid = parseInt(mid.toString())
    if(target>nums[mid]){
        for(i=0;i<=mid;i++)
        {nums.shift(i)}
        if(search(nums,target)==-1){return -1}
        return search(nums,target)+mid+1
    }else if(target<nums[mid]){
        for(i = nums.length-1;i>=mid;i--){
            nums.pop(i)
        }
        return search(nums,target)
    }else if(target===nums[mid]){
        return mid
    }else return -1
}
console.log(search(nums,target))
</script>
</body>
</html>